// $Id: headers.h 41 2011-04-15 15:44:51Z cedric.shih@gmail.com $
/*
 * Copyright (C) 2010 Cedric Shih <cedric.shih@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef HEADERS_H_
#define HEADERS_H_

#include <sys/tree.h>

#include "niohttp.h"

/**
 * @brief HTTP header entry.
 */
struct niohttp_headers_entry {
	char *name; /**< Parameter name. */
	char *value; /**< Parameter value. */
	struct niohttp_header node; /**< List node. */
	RB_ENTRY(niohttp_headers_entry) next;
};

RB_HEAD(niohttp_headers_tree, niohttp_headers_entry);

/**
 * @brief HTTP header.
 */
struct niohttp_headers {;
	struct niohttp_header_list list;
	struct niohttp_headers_tree tree;
	size_t size;
};

int niohttp_headers_entry_compare(struct niohttp_headers_entry *a,
		struct niohttp_headers_entry *b);

RB_PROTOTYPE(niohttp_headers_tree, niohttp_headers_entry, next,
		niohttp_headers_entry_compare);

struct niohttp_headers_entry *niohttp_headers_find(
		struct niohttp_headers *headers, const char *name);

int niohttp_headers_nset(struct niohttp_headers *headers,
		const char *name, size_t namelen,
		const char *value, size_t valuelen);

void niohttp_headers_remove_do(struct niohttp_headers *headers,
		struct niohttp_headers_entry *entry);

#endif /*HEADERS_H_*/
